﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Deployment.BuildManager.ExternalProcess.Common;
using Deployment.TeamFoundation.Entity;
using Deployment.TeamFoundation.Logic;

namespace Deployment.BuildManager.ExternalProcess.CheckInAssemblies
{
    public class BuildTask : IBuildTask
    {
        #region IBuildTask Members

        public SetupInfo Execute(SetupInfo info)
        {
            CheckInHtxSpkPackage(info);
            return info;
        }

        public void Cancel()
        {
            throw new NotImplementedException();
        }

        #endregion

        public void CheckInHtxSpkPackage(SetupInfo info)
        {
            this.SendMessage("Versionando o Build...");
            SourceControl.Instance.AddCheckinFileOrFolder("DeploymentPackager", info.CompiledUri + BuildConstants.PackageServerFolder, info.DownloadPath + Path.DirectorySeparatorChar + BuildConstants.PackageServerFolder);
        }

        #region [ Events ]

        public event EventHandler<MessageEventArgs> MessageReceived;

        private void SendMessage(string message)
        {
            if (MessageReceived != null)
            {
                MessageEventArgs eventArgs = new MessageEventArgs(message);
                Logger.Log(message, Logger.EntryType.Information);
                MessageReceived(this, eventArgs);
            }
        }

        #endregion [ Events ]
    }
}
